home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / CapFirst2 < prev    next >
Encoding:
Text File  |  1992-01-09  |  3.0 KB  |  90 lines  |  [TEXT/MPS ]

  1. #--------------------------------------------------------------------------------------------------------------------------------------------------- # 
  2. # CapFirst
  3. #  MPW Shell Script
  4. #  Written by Gina Cherry • September 16,1991
  5. #  Copyright:  © 1991 by Apple Computer, Inc., all rights reserved. 
  6. #
  7. #  Usage:  CapFirst [file]
  8. #
  9. #  Function:
  10. #  CapFirst capitalizes the first character of each line of a text file. CapFirst skips over blanks
  11. #  and tabs.  If the first character is not a letter, no change occurs. 
  12. #
  13. #  Note: CapFirst can be added to the Edit menu with the following command: 
  14. #
  15. #  AddMenu Edit 'CapFirst/6' 'CapFirst "{Active}"'
  16. #---------------------------------------------------------------------------------------------------------------------------------------------------
  17.  
  18. # If there is more than 1 parameter, write error message and exit script.
  19.    If {#} > 1
  20.    Echo "###Usage: {0} File"
  21.    Exit 1
  22.    End >> Dev:StdErr
  23.  
  24. # Do not exit on error.
  25.    Set Exit 0
  26.  
  27. # Searches should be case sensitive.
  28.    Set CaseSensitive 1
  29.  
  30. # If a parameter is given, File is set to the parameter.   Otherwise, File is the target file.
  31.    If {#} == 1
  32.    Set File "{1}"
  33.    Else
  34.    Set File "{Target}"
  35.    End
  36.  
  37. #  Record whether fName is already open.
  38.    Set fullName "`Files -i -f "{File}" ≥ Dev:Null`"
  39.    Set wasOpen `Evaluate "∂`Windows∂`" =~ /≈{fullName}≈/`
  40.  
  41. # Open input file.  Since diagnostic output from Open command is not needed, redirect it to bit bucket.
  42.    Open "{File}" ≥ Dev:Null
  43.  
  44. # If input file does not exist, exit script.
  45.    If {Status} != 0
  46.    Echo "###{0}: {File} is not a valid file."
  47.    Exit 1
  48.    End >> Dev:StdErr
  49.  
  50. # Mark currently selected text to restore state of window at end of script.
  51.    Mark -y § {0}.Selection "{File}"
  52.  
  53. # Position cursor at beginning of input file.
  54.    Find • "{File}"
  55.  
  56. # Save value of NewWindowRect to restore later.
  57.    Set OldWindowRect "{NewWindowRect}"
  58.  
  59. # Loop through lines in input file.
  60.    Loop
  61.  
  62.    # Position cursor at beginning of the current line in input file.
  63.    Find /•[ ∂t]*?/ "{File}" || Break
  64.  
  65.    (Evaluate "`Catenate "{File}".§`" =~ /([ ∂t]*)®1(?)®2≈/) > Dev:Null || Break
  66.  
  67.    # Check whether the selected character is a lowercase letter.
  68.    #   Note: Diagnostic output for the entire If statement is discarded because the If statement will
  69.    #   produce an error message if the selected text in the input file is a parenthesis.  This occurs
  70.    #   because the shell interprets the character as an unmatched parenthesis.
  71.    If "{®2}" =~ /[a-z]/
  72.    # If so, change it to an uppercase letter and echo the change to the temporary file,
  73.    #   overwriting the file's contents.
  74.    echo -n "{®1}{®2}" | Translate a-z A-Z > "{File}.§"
  75.  
  76.    End ≥ Dev:Null
  77.  
  78.    End
  79.  
  80. # Select the text that was originally selected in the input file.
  81.    Find {0}.Selection "{File}"
  82.  
  83. # Delete the marker from the input file.
  84.    Unmark {0}.Selection "{File}"
  85.  
  86. #  If the input file was not open to start with, close the file and save changes.
  87.     If !"{wasOpen}"
  88.    Close -y "{File}"
  89.    End
  90.